class Solution {
public:
    vector<vector<int>> ans;
    vector<int> res;
    void dfs(int k,int n,int begin,int sum ){
      if(sum == n&&k == 0){
        ans.push_back(res);
      }
      for(int i = begin;i < 10&&sum + i <= n;i++){
        sum += i;
        res.push_back(i);
        dfs(k-1,n,i+1,sum);

        sum -= i;
        res.pop_back();
      }
    }
    vector<vector<int>> combinationSum3(int k, int n) {
         dfs(k,n,1,0);
         return ans;
    }
};
